package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.Review;
import com.bcu.calculus.mapper.ReviewMapper;
import com.bcu.calculus.service.ReviewService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ReviewServiceImpl implements ReviewService {

    @Resource
    private ReviewMapper reviewMapper;

    @Override
    public Message<?> add(Review review) {
        review.setReviewUpdateTime(new Date());
        return reviewMapper.insertSelective(review) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> del(Integer reviewId) {
        return reviewMapper.deleteByPrimaryKey(reviewId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> update(Review review) {
        review.setReviewUpdateTime(new Date());
        return reviewMapper.updateByPrimaryKeySelective(review) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Review> selectByPK(Integer reviewId) {
        return Message.success(null).add(reviewMapper.selectByPrimaryKey(reviewId));
    }

    @Override
    public Message<List<Review>> selectAll() {
        return Message.success(null).add(reviewMapper.selectAll());
    }

    @Override
    public Message<Review> selectBySendId(String sendId) {
        return Message.success(null).add(reviewMapper.selectBySendId(sendId));
    }
}
